//
//  themeCell.m
//  GIFShow
//
//  Created by lanou11air029 on 15/4/24.
//  Copyright (c) 2015年 CK. All rights reserved.
//

#import "themeCell.h"
#import "ImageButton.h"
#import "MySettingOptions.h"
@interface themeCell ()
@property (nonatomic, strong) UILabel * textTitleLabel;
@end

@implementation themeCell

- (void)awakeFromNib {
    // Initialization code
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupSubViews];
    }
    return self;
}

-(void)setupSubViews{
    
    CGRect screenBounds = [UIScreen mainScreen].bounds;
    CGFloat orignY = screenBounds.size.height * 0.09;
    CGFloat btnWidth = screenBounds.size.width * 0.25;
    CGFloat btnHeight = screenBounds.size.height * 0.24;
    
    self.textTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, 100, screenBounds.size.height * 0.085)];
    self.textTitleLabel.text = @"设置主题";
    self.textTitleLabel.font = [UIFont systemFontOfSize:18];
    [self.contentView addSubview:self.textTitleLabel];
    
    ImageButton * ibtn1 = [ImageButton buttonWithType:UIButtonTypeSystem];
    ibtn1.frame = CGRectMake(0, orignY, btnWidth, btnHeight);
    [ibtn1 setImage:[UIImage imageNamed:@"back01"] forState:UIControlStateNormal];
    [ibtn1 setTitle:@"星光璀璨" forState:UIControlStateNormal];
    [self.contentView addSubview:ibtn1];
    [ibtn1 addTarget:self action:@selector(didClickThemeChangeButton:) forControlEvents:UIControlEventTouchUpInside];
    
    ImageButton * ibtn2 = [ImageButton buttonWithType:UIButtonTypeSystem];
    ibtn2.frame = CGRectMake(btnWidth, orignY, btnWidth, btnHeight);
    [ibtn2 setImage:[UIImage imageNamed:@"back02"] forState:UIControlStateNormal];
    [ibtn2 setTitle:@"金色闪光" forState:UIControlStateNormal];
    [self.contentView addSubview:ibtn2];
    [ibtn2 addTarget:self action:@selector(didClickThemeChangeButton:) forControlEvents:UIControlEventTouchUpInside];

    ImageButton * ibtn3 = [ImageButton buttonWithType:UIButtonTypeSystem];
    ibtn3.frame = CGRectMake(2*btnWidth, orignY, btnWidth, btnHeight);
    [ibtn3 setImage:[UIImage imageNamed:@"back03"] forState:UIControlStateNormal];
    [ibtn3 setTitle:@"冰雪物语" forState:UIControlStateNormal];
    [self.contentView addSubview:ibtn3];
    [ibtn3 addTarget:self action:@selector(didClickThemeChangeButton:) forControlEvents:UIControlEventTouchUpInside];

    ImageButton * ibtn4 = [ImageButton buttonWithType:UIButtonTypeSystem];
    ibtn4.frame = CGRectMake(3*btnWidth, orignY, btnWidth, btnHeight);
    [ibtn4 setImage:[UIImage imageNamed:@"back04"] forState:UIControlStateNormal];
    [ibtn4 setTitle:@"粉红心情" forState:UIControlStateNormal];
    [self.contentView addSubview:ibtn4];
    [ibtn4 addTarget:self action:@selector(didClickThemeChangeButton:) forControlEvents:UIControlEventTouchUpInside];
}
-(void)didClickThemeChangeButton:(UIButton *)button{
    if ([button.titleLabel.text isEqualToString:@"星光璀璨"]) {
        [[MySettingOptions defaultOptions]setBackColor:@"back01"];
    }
    if ([button.titleLabel.text isEqualToString:@"金色闪光"]) {
        [[MySettingOptions defaultOptions]setBackColor:@"back02"];
    }
    if ([button.titleLabel.text isEqualToString:@"冰雪物语"]) {
        [[MySettingOptions defaultOptions]setBackColor:@"back03"];
    }
    if ([button.titleLabel.text isEqualToString:@"粉红心情"]) {
        [[MySettingOptions defaultOptions]setBackColor:@"back04"];
    }
    [[NSUserDefaults standardUserDefaults] synchronize];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"ChangeTheme" object:button.titleLabel.text];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    CGFloat height = [UIScreen mainScreen].bounds.size.height;
    CGRect frame = self.contentView.frame;
    if(selected){
        frame.size.height = height*0.34;
        [UIView animateWithDuration:0.4 animations:^{
            self.contentView.frame = frame;
            self.contentView.backgroundColor = [UIColor colorWithRed:0.95 green:1 blue:0.95 alpha:0.96];
        }];
        self.contentView.clipsToBounds = YES;
    }else{
        frame.size.height = height*0.085;
        [UIView animateWithDuration:0.4 animations:^{
            self.contentView.frame = frame;
            self.contentView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.91];
        }];
        self.contentView.clipsToBounds = YES;
    }

    // Configure the view for the selected state
}

@end
